#!/bin/sh/env python
#encoding: utf-8

'''
  install python 2.7.5
  export PYTHONPATH=/usr/local/backup/python/lib/
'''
import os 
import fileinput
from time import sleep
#import logging 

#logging.basicConfig(filename='init.log',level=logging.DEBUG)


def init():
    initPath()
    initEnv()
    install_python()
    setupYum()
    install_python_module()
    
def initPath():
    print "start mkdir in \n------------------------"
    os.system("sh ./sh/1_init_path.sh")
    
def initEnv():
    print 'init env for centos now:...\n----------------------'
    os.system("sh ./sh/2_init_env.sh")
    sleep(1)
    
def install_python():
    print 'start download python:...\n----------------------'
    os.system("sh ./sh/3_install_python.sh")
    #setup Modules/Setup.dist
    input=fileinput.input("file/Python-2.7.5/Modules/Setup.dist", inplace=1)
    for line in input:
      if line.startswith("#readline"):
        line=line.replace("#readline","readline")
      print line,
    input.close()
    print "start configure and make install ...\n-----------------"
    os.system("sh ./sh/4_install_python.sh")
    
def setupYum():
    print 'reconfig yum\n--------------------'
    #reconfig yum
    input=fileinput.input("/usr/bin/yum", inplace=1)
    for line in input:
        if line.startswith("#!/usr/bin/python"):
	          line=line.replace("#!/usr/bin/python","#!/usr/bin/python2.6")
        print line,
    input.close()
    
def install_python_module():
    print 'install setuptools\n-------------'
    os.system("sh ./sh/5_install_python_module.sh")
    print 'install pip,fabric,pycrypto ...\n--------------'
    os.system("sh ./sh/6_install_python_module.sh")
    
init()
